zoom = 10;

sendSMS = function(){
	if ($("#loc").val().length >= 3 &&
		$("#txt").val().length >= 2 && 
		$("#txt").val().length <= 255){
		$.ajax({
			type: "GET",
			dataType: "json",
			data:"loc="+$("#loc").val()+"&txt="+$("#txt").val(),
			url: "sendSMS.php",
			success: actualizarContacto,
			async: false,
			cache:false
		});
	}
}

InitMap = function() {
	var humanResources = [ {lat:-34.685893, lng : -58.477135, name : "Federico", address : "Piedrabuena 4753" }];
	var homeLatLng = new google.maps.LatLng(-34.685893,-58.477135);
	var myOptions = {
  		zoom: 4,
  		center: homeLatLng,
  		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById("map"),myOptions);
	var radio = $("#radio").val() * 1000;
	var populationOptions = {
      strokeColor: "#FF0000",
      strokeOpacity: 0.8,
      strokeWeight: 2,
      fillColor: "#FF0000",
      fillOpacity: 0.35,
      map: map,
      center: homeLatLng,
      radius: radio
    };
    cityCircle = new google.maps.Circle(populationOptions);

}


obtenerContactos = function(){
		if ($("#loc").val().length >= 3)

	$.ajax({
		type: "GET",
		dataType: "json",
		data:"loc="+$("#loc").val(),
		url: "getContactos.php",
		success: actualizarContacto,
		async: false,
		cache:false
	});
}



actualizarContacto = function (json){
	lista = json.contactos;
	//$("#contactos").html(lista.length);
	
	if($("#map").html()!='') zoom = map.getZoom();
	
	$("#contactos").html('');
		$("#map").html('');
	
	if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
		
        map.setCenter(new GLatLng(0, 0),zoom);
		
		
		
		map.addControl(new GMapTypeControl());
		map.addControl(new GLargeMapControl());
		map.addControl(new GScaleControl());
		map.addControl(new GOverviewMapControl());
		
		
		//DEFINO EL ICONO
		var iconoMarca = new GIcon(G_DEFAULT_ICON);
		iconoMarca.image = "img/blue.png"; 
		iconoMarca.iconSize = new GSize(32,32);
     }




	for (c=0;c<lista.length;c++){
		
		marker = new GMarker(new GLatLng(lista[c].lat,lista[c].lon),iconoMarca);
		map.setCenter(new GLatLng(lista[c].lat,lista[c].lon));
		
		
		marker.setPoint(new GLatLng(lista[c].lat,lista[c].lon));
		//addAMarker(map,marker,[lista[c].lat,lista[c].lon]);
		
		map.addOverlay(marker);
		
		$("#contactos").html($("#contactos").html() );
    	 $("#contactos").html(
    	 $("#contactos").html()
    	 + "<br/>"   
    	 + lista[c].apellido + ", " 
    	 + lista[c].nombre + "-" 
    	 + lista[c].DomLocalidad + "-" 
    	 + lista[c].DomTelefMovil
    	 );
	}
}
